using System;

namespace Slf.Samples.ExceptionLogging
{
  class Program
  {
    static void Main(string[] args)
    {
      //configure a logger (log the message to the console)
      LoggerService.SetLogger(new ConsoleLogger());

      //perform a legal calculation - the result will be logged to SLF
      Divide100By(2);

      //perform illegal calculation - the exception will be caught and logged to SLF
      Divide100By(0);

      Console.ReadLine();
    }



    private static void Divide100By(int number)
    {
      ILogger logger = LoggerService.GetLogger();

      try
      {
        int result = 100/number;

        //log an info with the result
        logger.Info("Calculated 100 by {0}. Result is: {1}", number, result);
      }
      catch (Exception e)
      {
        //log the exception with a formatted custom message
        logger.Error(e, "Exception occurred when dividing 100 by {0}.", number);
      }
    }

  }
}